using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Linq2Crm.ObjectModel.DomainObject;

namespace Linq2Crm.Request
{
	public class GetRequest : RequestBase
	{
		private GetRequest(Type type)
			: base(type)
		{
		}

		public Action<GetResponse> Callback { get; set; }

      public IProgress<int> ReportProgress { get; set; }

		public static GetRequest Create<T>()
			where T: IDomainObject
		{
			return new GetRequest(typeof (T))
			       	{
			       		Query = new List<T>().AsQueryable()
			       	};
		}

		public View UseView { get; set; }

		public bool BackgroundTask { get; set; }

		internal override void Execute()
		{
			DomainObjectContext.Instance.ExecuteGetRequest(this);
		}

		internal override async Task<ResponseBase> ExecuteAsync()
		{
			var response = await DomainObjectContext.Instance.ExecuteGetRequestAsync(this, ReportProgress);
			return response;
		}
	}
}